Page({
    data: {
      params: {
        page: 1,
        size: 999999,
        id: ''
      },

      params2: {
        bookAfterReadingId: '',
        option: ''
      },
      userName: '',
      headPic: '',
      content: '',
      date:'',

      thumbType: '',//判断点赞还是踩一下
      thumbUpNum: 0,
      thumbDownNum: 0
    },
    onLoad (options) {
      this.data.params2.bookAfterReadingId = options.feelid
      this.setData({
        params: {
          page: 1,
          size: 999999,
          id: options.feelid
        },
        bookId: options.bookId,
        coverPic: options.coverPic,
        name: options.name
      })

      this.getFeelList(this.data.params)
    },

    getFeelList (params) {
      console.log(params)

      var _this = this
      wx.request({
        url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/book/afterReading/find/auth',
        data: params,
        method: 'POST',
        header: {
          "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token" : wx.getStorageSync('token'),
          "uid" : wx.getStorageSync('uuid')
        },
        success: (res) => {
          if (res.data.code == 200) {
            _this.setData({
              userName: res.data.data.userName,
              headPic: res.data.data.headPic,
              content: res.data.data.content,
              date: res.data.data.date.replace(/-/g,'.'),
              isThumb: res.data.data.isThumb,
              thumbType: res.data.data.thumbType,
              thumbUpNum: res.data.data.thumbUpNum,
              thumbDownNum: res.data.data.thumbDownNum
            })
            var pages = getCurrentPages();
            var prevPage = pages[pages.length - 2];
            prevPage.dianzanLoad(_this.data.params2.bookAfterReadingId,_this.data.isThumb, _this.data.thumbType, _this.data.thumbUpNum)
          }else{
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        }
      })
    },

  //点赞和菜
  dianzan (e) {
    console.log(e)

    var options = e.currentTarget.dataset.option
    var option = "params2.option"
    this.setData({
      [option]: options
    })
    this.dianApi(this.data.params2)
  },


  dianApi (params) {
    var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/book/afterReading/thumb/auth',
      data: params,
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
      "token" : wx.getStorageSync('token'),
        "uid" : wx.getStorageSync('uuid')
      },
      success: (res) => {

        if (res.data.code) {
          if (params.option == 1) {
            if (_this.data.isThumb == 1 && _this.data.thumbType == 1) {
              wx.showToast({
                title: '取消成功',
                icon: 'none'
              })
              _this.getFeelList(_this.data.params)
            }else{
              wx.showToast({
                title: '点赞成功',
                icon: 'none'
              })
              _this.getFeelList(_this.data.params)
            }

          }else if (params.option == 2) {
            if (_this.data.isThumb==1&&_this.data.thumbType == 2) {
              wx.showToast({
                title: '取消成功',
                icon: 'none'
              })
              _this.getFeelList(_this.data.params)
            } else {
              wx.showToast({
                title: '点踩成功',
                icon: 'none'
              })
              _this.getFeelList(_this.data.params)
            }
          }
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
        // console.log(res)
      }
    })
  },


  dianzan2 () {
    wx.showToast({
      title: '您已点赞',
      icon: 'none'
    })
  },


  onShareAppMessage (res) {

    var _this = this
    if (res.from == 'button') {
      console.log(res.target, res)
    }

    return {
      title: _this.data.name,
      path: '/package/index/pages/bookdetail/bookdetail?bookId=' + _this.data.bookId,
      imageUrl: _this.data.coverPic
    }
  }

})
